import { useValidateStore } from '@/store/useValidateStore'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const FieldValidate = ({ errors, name }: { errors: any; name: string }) => {
  const errorStoreData = useValidateStore((s) => s.errors)
  errors = errors.map((error: { message: string }) => (typeof error === 'string' ? error : error.message))
  if (errors.length === 0 && !errorStoreData[name]) return <div className="my-3"></div>
  return (
    <div className="border bg-red-100 text-xs h-6 flex items-center px-2 my-1 text-accent-foreground rounded-sm">
      {errors.join('') || errorStoreData[name].join('')}
    </div>
  )
}
